#include<iostream>
#include<vector>
using namespace std;
class Solution {
public:
    vector<int> plusOne(vector<int>& digits) {
        vector<int>ret(digits.rbegin(), digits.rend());
        ret[0] += 1;
        int left = 0;
        while (left < ret.size())
        {
            if (ret[left] > 9)
            {
                ret[left] = 0;
                if (left < ret.size() - 1)
                    ret[++left] += 1;
                else
                    ret.push_back(1);

            }
            else break;
        }
        if (ret.size() == left)ret.push_back(1);
        reverse(ret.begin(), ret.end());
        return ret;
    }
};